#include <iostream>
using namespace std;
void numbersAppearOnce(int arr[],int length)
{
	int a,b;
	//a用作sum，记录所有值的异或
	a = arr[0];
	for(int i = 1; i != length ; ++i)
	{
		a^=arr[i];
	}
	//b用作index，记录第一个为1的位
	cout<<"a : "<<a<<endl;
	b = 1;
	while((a & 1) == 0)
	{
		a>>=1;
		b<<=1;
	}
	cout<<b<<endl;
	cout<<"split arr"<<endl;
	//分割数组为两个子数组，每个子数组包含一个仅出现一次的数
	int arr1[length] = {0},arr2[length] = {0};
	int length1 = 0,length2 = 0;
	for(int i = 0 ; i != length ; ++i)
	{
		if((arr[i] & b) == 0)
			arr1[length1++] = arr[i];
		else
			arr2[length2++] = arr[i];
	}
	cout<<"split finish"<<endl;
	cout<<length1<<endl;
	for(int i = 0 ; i < length1 ; ++i)
	{
		cout<<arr1[i]<<",";
	}
	cout<<endl;
	for(int i = 0 ; i < length2 ; ++i)
	{
		cout<<arr2[i]<<",";
	}
	cout<<endl;
	if(length1>0)
	{
		a = arr1[0];
		for(int i = 1 ; i != length1; ++i)
		{
			a^=arr1[i];
		}
	}
	if(length2>0)
	{
		b = arr2[0];
		for(int i = 1 ; i != length2; ++i)
		{
			b ^= arr2[i];
		}
	}
	cout<<"output : "<<endl;
	cout<<a<<" , "<<b<<endl;
}
int main()
{
	int arr[] = {2,4,3,6,3,2,5,5};
	int arr1[] = {2,4};
	numbersAppearOnce(arr,8);
	numbersAppearOnce(arr1,2);

	system("pause");
	return 0;
}